package jsp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 石小俊
 * @date 2023年10月23日 14:49
 */
@WebServlet("/show/*")
public class ShowServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String encoding = getServletContext().getInitParameter("encoding");
        System.out.println("encoding:"+encoding);
//        request.getRequestDispatcher("/WEB-INF/a/test01.jsp").forward(request,response);
        // /web/show/test  -->   /test -->  /WEB-INF/test.jsp
        String uri = request.getRequestURI();
        System.out.println("uri:"+uri); // /web/show/test

        String contextPath = request.getContextPath();
        System.out.println("contextPath:"+contextPath); // web

        String servletPath = request.getServletPath();
        System.out.println("servletPath:" + servletPath);   // /show


        String path =  uri.substring((contextPath+servletPath).length());
        System.out.println("path:"+path);    // /test

        request.getRequestDispatcher("/WEB-INF"+path+".jsp").forward(request,response);
    }
}
